<template>
       <div class="bg-white top">

         <el-form :inline="true" v-show="isSearchCollapse" class="query-form" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>
           <el-form-item prop="name">
                  <el-input size="small" v-model="searchForm.name" placeholder="姓名" clearable></el-input>
           </el-form-item>
           <el-form-item prop="institute">
                  <el-input size="small" v-model="searchForm.institute" placeholder="学院" :disabled="role > 1" clearable></el-input>
           </el-form-item>
           <el-form-item prop="grade">
                  <el-input size="small" v-model="searchForm.grade" placeholder="年级" :disabled="role > 2" clearable></el-input>
           </el-form-item>
           <el-form-item prop="classe">
                  <el-input size="small" v-model="searchForm.classe" placeholder="班级" :disabled="role > 3" clearable></el-input>
           </el-form-item>
           <el-form-item prop="teacher">
                  <el-input size="small" v-model="searchForm.currentInstructor" placeholder="审核人" :disabled="role > 2" clearable></el-input>
           </el-form-item>
           <el-form-item prop="addReason">
                  <el-input size="small" v-model="searchForm.addReason" placeholder="加分原因" :disabled="role > 2" clearable></el-input>
           </el-form-item>
           <!-- <el-select v-model="searchForm.evaluate" placeholder="是否评价">
             <el-option
               v-for="item in options"
               :key="item.value"
               :label="item.label"
               :value="item.value">
             </el-option>
           </el-select> -->
           <el-form-item prop="studentId">
                  <el-input size="small" v-model="searchForm.studentId" placeholder="学号" clearable></el-input>
           </el-form-item>
           <el-form-item prop="state">
                  <el-input size="small" v-model="searchForm.state" placeholder="审核状态" clearable></el-input>
           </el-form-item>
           <el-form-item prop="addPoint">
                  <el-input size="small" v-model="searchForm.addPoint" placeholder="加分数" :disabled="role > 2" clearable></el-input>
           </el-form-item>
<!--           <el-date-picker
             v-model="searchForm.addTime"
             type="date"
             placeholder="选择申请日期时间"
             value-format="yyyy-MM-dd"
             align="right"
             :picker-options="pickerOptions">
           </el-date-picker>
           <el-date-picker
             v-model="searchForm.auditTime"
             type="date"
             placeholder="选择审核日期时间"
             value-format="yyyy-MM-dd"
             align="right"
             :picker-options="pickerOptions">
           </el-date-picker> -->
           <el-form-item prop="relationship">
                  <el-input size="small" v-model="searchForm.relationship" placeholder="与学生的关系" :disabled="role > 2" clearable></el-input>
           </el-form-item>
               <!-- 搜索框-->
             <el-form-item>
               <el-button type="primary" @click="refreshList()" size="small">查询</el-button>
               <el-button @click="resetSearch()" size="small">重置</el-button>
             </el-form-item>
         </el-form>
           <!-- 导入导出-->
         <el-dialog  title="导入Excel" :visible.sync="isImportCollapse">
             <el-form size="small" :inline="true" v-show="isImportCollapse"  ref="importForm">
                <el-form-item>
                 <el-button type="default" @click="downloadTpl()" size="small">下载模板</el-button>
                </el-form-item>
                <el-form-item prop="loginName">
                   <el-upload
                     class="upload-demo"
                     :action="`${this.$http.BASE_URL}/studentevaluate/studentEvaluate/import`"
                     :on-success="uploadSuccess"
                      :show-file-list="true">
                     <el-button size="small" type="primary">点击上传</el-button>
                     <div slot="tip" class="el-upload__tip">只允许导入“xls”或“xlsx”格式文件！</div>
                   </el-upload>
               </el-form-item>
             </el-form>
         </el-dialog>
         <el-row>
           <el-button-group class="pull-right">
             <el-button
               type="default"
               size="small"
               icon="el-icon-search"
               @click="isSearchCollapse = !isSearchCollapse, isImportCollapse=false">
             </el-button>
               <el-button v-if="hasPermission('studentevaluate:studentEvaluate:import')" type="default" size="small" icon="el-icon-upload2" title="导入" @click="isImportCollapse = !isImportCollapse"></el-button>
               <el-button v-if="hasPermission('studentevaluate:studentEvaluate:export')" type="default" size="small" icon="el-icon-download" title="导出" @click="exportExcel()"></el-button>
               <el-button
                 type="default"
                 size="small"
                 icon="el-icon-refresh"
                 @click="refreshList">
               </el-button>
           </el-button-group>
         </el-row>
    <el-table
      :data="dataList"
      v-loading="loading"
      size="small"
      height="800px"
      class="table">
      <el-table-column
          prop="name"
          show-overflow-tooltip
          sortable="custom"
          label="姓名">
        </el-table-column>
      <el-table-column
          prop="institute"
          show-overflow-tooltip
          sortable="custom"
          label="学院">
        </el-table-column>
      <el-table-column
          prop="grade"
          show-overflow-tooltip
          sortable="custom"
          label="年级">
        </el-table-column>
      <el-table-column
          prop="classe"
          show-overflow-tooltip
          sortable="custom"
          label="班级">
        </el-table-column>
      <el-table-column
          prop="studentId"
          show-overflow-tooltip
          sortable="custom"
          label="学号">
        </el-table-column>
      <el-table-column
          prop="currentMoraleduPoint"
          show-overflow-tooltip
          sortable="custom"
          label="目前德育分">
        </el-table-column>
          <el-table-column
              prop="addReason"
              label="加分原因">
            </el-table-column>
          <el-table-column
              prop="addTime"
              label="加分时间">
            </el-table-column>
          <el-table-column
              prop="addPoint"
              label="加分数">
            </el-table-column>
          <el-table-column
              prop="state"
              label="审核状态">
              <template slot-scope="scope">
                 {{ $dictUtils.getDictLabel("audit_status", scope.row.state, '-') }}
              </template>
            </el-table-column>
            <el-table-column
                prop="auditTime"
                label="审批时间">
              </el-table-column>
              <el-table-column
                  prop="currentInstructor"
                  show-overflow-tooltip
                  sortable="custom"
                  label="审核人">
                </el-table-column>
            <el-table-column
              prop="addEnclosure"
              label="附件">
              <template slot-scope="scope" v-if="scope.row.addEnclosure">
                <el-image
                  style="height: 50px;width:50px;margin-right:10px;"
                  :src="src"
                  v-for="(src, index) in scope.row.addEnclosure.split(',')" :key="index"
                  :preview-src-list="scope.row.addEnclosure.split(',')">
                </el-image>
              </template>
            </el-table-column>
<!--        <el-table-column
          header-align="center"
          align="center"
          fixed="right"
          :key="Math.random()"
          width="200"
          label="操作">
          <template  slot-scope="scope">
            <el-button v-if="hasPermission('selectcontent:selectContent:view')" type="text" icon="el-icon-view" size="small" @click="view(scope.row.id)">查看</el-button>
            <el-button v-if="hasPermission('selectcontent:selectContent:edit')" type="text" icon="el-icon-edit" size="small" @click="edit(scope.row.id)">修改</el-button>
            <el-button v-if="hasPermission('selectcontent:selectContent:del')" type="text"  icon="el-icon-delete" size="small" @click="del(scope.row.id)">删除</el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageNo"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="total"
        background
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
      </div>
</template>

<script>
  export default {
    data () {
      return {
        searchForm: {
          name: '',
          institute: '',
          grade: '',
          classe: '',
          studentId: '',
          currentInstructor: '',
          addReason: '',
          state: '',
          addTime: '',
          addPoint: '',
          auditTime: ''
        },
        dataList: [],
        pageNo: 1,
        pageSize: 10,
        total: 0,
        orderBy: '',
        dataListSelections: [],
        isImportCollapse: false,
        loading: false,
        checkAll: false, // 全选
        checkA: false, // 状态全选
        checkedGrades: [], // 已选中的
        allSelect: [], // 可选项, 采用的是计算机学院的年级
        isIndeterminate: true,
        isIndetermina: true,
        id: '',
        state: ['在籍', '休学', '保留学籍'],
        checkedstate: [], // 选择的状态
        isSearchCollapse: false
      }
    },
    components: {

    },
    activated () {
      this.refreshList()
    },
    methods: {
      // 获取数据列表
      refreshList () {
        this.loading = true
        this.$http({
          url: '/moredumain/studentMoreduMain/queryDetail',
          method: 'get',
          params: {
            'pageNo': this.pageNo,
            'pageSize': this.pageSize,
            'orderBy': this.orderBy,
            ...this.searchForm
          }
        }).then(({data}) => {
          if (data && data.success) {
            this.dataList = data.page.list
            this.total = data.page.count
            this.loading = false
          }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageNo = 1
        this.refreshList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageNo = val
        this.refreshList()
      },
      // 多选
      // selectionChangeHandle (val) {
      //   this.dataListSelections = val
      // },

    // 排序
      sortChangeHandle (obj) {
        if (obj.order === 'ascending') {
          this.orderBy = obj.prop + ' asc'
        } else if (obj.order === 'descending') {
          this.orderBy = obj.prop + ' desc'
        } else {
          this.orderBy = ''
        }
        this.refreshList()
      },
      // 新增
      add () {
        this.$refs.selectContentForm.init('add', '')
      },
      // 修改
      edit (id) {
        id = id || this.dataListSelections.map(item => {
          return item.id
        })[0]
        this.$refs.selectContentForm.init('edit', id)
      },
      // 查看
      view (id) {
        this.$refs.selectContentForm.init('view', id)
      },
      // 删除
      del (id) {
        let ids = id || this.dataListSelections.map(item => {
          return item.id
        }).join(',')
        this.$confirm(`确定删除所选项吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.$http({
            url: '/selectcontent/selectContent/delete',
            method: 'delete',
            params: {'ids': ids}
          }).then(({data}) => {
            if (data && data.success) {
              this.$message.success(data.msg)
              this.refreshList()
            }
            this.loading = false
          })
        })
      },
      // 导入成功
      uploadSuccess (res, file) {
        if (res.success) {
          this.$message.success({dangerouslyUseHTMLString: true,
            message: res.msg})
        } else {
          this.$message.error(res.msg)
        }
      },
      // 下载模板
      downloadTpl () {
        this.$utils.download('/selectcontent/selectContent/import/template')
      },
      exportExcel () {
        let params = {
          ...this.searchForm
        }
        this.$utils.download('/selectcontent/selectContent/export', params)
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.refreshList()
      },
      handleCheckAllChange (val) {
        this.checkedGrades = val ? this.allSelect : []
        this.isIndeterminate = false
      },
      handleCheckedCitiesChange (value) {
        let checkedCount = value.length
        this.checkAll = checkedCount === this.allSelect.length
        this.isIndeterminate = checkedCount > 0 && checkedCount < this.allSelect.length
      },
      handleCheckAllChan (val) {
        this.checkedState = val ? this.state : []
        this.isIndetermina = false
      },
      handleCheckedCitiesChan (value) {
        let checkedCount = value.length
        this.checkA = checkedCount === this.state.length
        this.isIndetermina = checkedCount > 0 && checkedCount < this.state.length
      }
    }
  }
</script>


<style>
</style>
